/*******************************************************************************
** WHAT: 	Replication file for the paper
			"Artisanal or Industrial Conflict Minerals",
			by Nik Stoop, Marijke Verpoorten, Peter van der Windt.
				
			Below you find the code to regenerate the Tables and Figures,
			presented in the order in which they appear in the Paper and Supplementary files.
			
** WHEN: 	June '19

** WHO:	 	Nik Stoop, nik.stoop@uantwerp.be
********************************************************************************/


********************************************************************************
*** Data sources
********************************************************************************
/* 	Detailed info on the data sources is included in the Paper and Supplementary files
	- Conflict data from ACLED
	- Mining data from IPIS and CAMI
	- Mineral price data from metalprices.com
	- Rainfall data from CRU

	
********************************************************************************
*** Correction for spatial & serial correlation
********************************************************************************
	Throughout the paper we present results with standard errors that have been corrected
	for spatial and location-specific serial correlation.
	
	We follow the methodology of:
	Conley (1999). GMM estimation with cross sectional dependence. Journal of Econometrics, 92 (1) 1-45.
	
	We use the Stata routine my_reg2hdfespatial.ado, which is available in the supplementary files of:
	Berman et al. (2017). This mine is mine! How minerals fuel conflicts in Africa. American Economic Review, 107 (6).
	
	The routine is based on ols_spatial_HAC.ado, developed by:
	Hsiang, et al. (2011). Civil Conflicts Are Associated with the Global Climate. Nature, 476: 438-41 
	
	and its extension regh2dfespatial.ado, developed by Thiemo Fetzer and based on:
	Guimaraes and Portugal. 2010. A Simple Feasible Alternative Procedure to Estimate Models with High-Dimensional Fixed Effects. Stata Journal 10: 628-49. */
	
	
********************************************************************************
*** Set directory
********************************************************************************
clear all
set more off	
cap cd "...set your directory.../"


********************************************************************************
*** Fig 1: Eastern Congo
********************************************************************************
* maps created in QGIS


********************************************************************************
*** Fig 2: Sources of variation in the Congolese mining sector
********************************************************************************
use "AICM.dta",clear
	
	set scheme s1mono
	twoway (line mp_gold modate, sort), title(Gold,size (medium)) ylabel(, format(%9.0g)) xlabel(528 552 576 600 624 648 671,labsize(medsmall)valuelabels angle(stdarrow)) xtitle(, size(zero)) ytitle(, size(zero)) 
		graph copy Graph a, replace
	twoway (line mp_tin modate, sort), title(Tin,size (medium)) ylabel(, format(%9.0g)) xlabel(528 552 576 600 624 648 671,labsize(medsmall)valuelabels angle(stdarrow)) xtitle(, size(zero)) ytitle(, size(zero))
		graph copy Graph b, replace
	twoway (line mp_tantalum modate, sort), title(Tantalum,size (medium)) ylabel(, format(%9.0g)) xlabel(528 552 576 600 624 648 671,labsize(medsmall)valuelabels angle(stdarrow)) xtitle(, size(zero)) ytitle(, size(zero))	
		graph copy Graph c, replace
	twoway (line mp_tungsten modate, sort), title(Tungsten,size (medium)) ylabel(, format(%9.0g)) xlabel(528 552 576 600 624 648 671,labsize(medsmall)valuelabels angle(stdarrow)) xtitle(, size(zero)) ytitle(, size(zero))
		graph copy Graph d, replace
	twoway (line mp_copper modate, sort), title(Copper,size (medium)) ylabel(, format(%9.0g)) xlabel(528 552 576 600 624 648 671,labsize(medsmall)valuelabels angle(stdarrow)) xtitle(, size(zero)) ytitle(, size(zero))
		graph copy Graph e, replace
	
	graph combine a b e c d, scheme(s1color)	


********************************************************************************
*** Table 1: Summary statistics
********************************************************************************
use "AICM.dta",clear	
	
	bysort cell: gen x=_n	
	
	* overall incidence of conflict events
		sum battles violence riots looting if x==1

	* # of months with conflict events
		sum mbattles mviolence mriots mlooting if x==1
		
	* monthly incidence of conflict events
		sum dbattles dviolence driots dlooting
		
	* ASM
		sum asm gold_asm t3_asm if x==1
		sum asmnr gold_asmnr t3_asmnr if x==1
	
	* LSM
		sum LSMr LSMp
			
	
********************************************************************************
*** Fig 3: Location of conflict events, ASM sites and LSM concessions
********************************************************************************
* maps created in QGIS



********************************************************************************
*** Table 2: Mineral prices and conflict
********************************************************************************
use "AICM.dta",clear	

	* Panel A: LSM mines
	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles lsmXprice if nochange==1 , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence lsmXprice if nochange==1 , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dbattles lsmXprice , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence lsmXprice , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "Table2a.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 	

	* Panel B: LSM and ASM mines
	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles lsmXprice asmXprice if nochange==1 , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence lsmXprice asmXprice if nochange==1 , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dbattles lsmXprice asmXprice , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence lsmXprice asmXprice , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "Table2b.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 	
	
	
********************************************************************************
*** Fig 4: Expansion of large-scale mining in a cell
********************************************************************************
* figure created in powerpoint



********************************************************************************
*** Table 3: Expansion of LSM and conflict
********************************************************************************
use "AICM.dta",clear	
	
	* Panel A
	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles asmXprice LSMrXprice LSMpXprice LSMr LSMp , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence asmXprice LSMrXprice LSMpXprice LSMr LSMp , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting asmXprice LSMrXprice LSMpXprice LSMr LSMp , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots asmXprice LSMrXprice LSMpXprice LSMr LSMp , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "Table3a.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 
	
	* Panel B
	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "Table3b.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 



********************************************************************************
*** Table A.1: Excluding tantalum
********************************************************************************
use "AICM.dta",clear	

	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm if drop_tant!=1, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm if drop_tant!=1 , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm if drop_tant!=1 , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm if drop_tant!=1 , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "TableA1.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 
	

********************************************************************************
*** Table A.2: Excluding the Dodd-Frank period
********************************************************************************
use "AICM.dta",clear	

	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm if DF!=1, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm if DF!=1 , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm if DF!=1 , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm if DF!=1 , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "TableA2.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 
	
	
********************************************************************************
*** Table A.3: ASM price effect during the Dodd-Frank period
********************************************************************************
use "AICM.dta",clear		
	
	gen DF_asmXprice=DF*asmXprice
	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles asmXprice DF_asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence asmXprice DF_asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting asmXprice DF_asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots asmXprice DF_asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "TableA3.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 
	
	
********************************************************************************
*** Table A.4: Controlling for 12-month dynamic and spatial conflict lags
********************************************************************************
use "AICM.dta",clear	
	
	local conflict "l1conflict l2conflict l3conflict l4conflict l5conflict l6conflict l7conflict l8conflict l9conflict l10conflict l11conflict l12conflict conflict_adj l1conflict_adj l2conflict_adj l3conflict_adj l4conflict_adj l5conflict_adj l6conflict_adj l7conflict_adj l8conflict_adj l9conflict_adj l10conflict_adj l11conflict_adj l12conflict_adj"
	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm `conflict', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm `conflict', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm `conflict', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm `conflict', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "TableA4.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 
		
	
********************************************************************************
*** Table A.5: Controlling for province specific linear time trends
********************************************************************************
use "AICM.dta",clear	
	
	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm npyrmth1-npyrmth11, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm npyrmth1-npyrmth11, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm npyrmth1-npyrmth11, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm npyrmth1-npyrmth11, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "TableA5", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 
		
	
***************************************************************************************
*** Table A.6: Estimation on restricted sample of cells with LSM production concessions
***************************************************************************************
use "AICM.dta",clear		
	
	bysort cell:egen everlsmp=max(LSMp)
	replace everlsmp=1 if everlsmp!=0
	eststo clear
	eststo:xi:quietly my_reg2hdfespatial dbattles asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm if everlsmp==1, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo:xi:quietly my_reg2hdfespatial dviolence asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm if everlsmp==1, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo:xi:quietly my_reg2hdfespatial dlooting asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm if everlsmp==1, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo:xi:quietly my_reg2hdfespatial driots asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm if everlsmp==1, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "TableA6", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 	
	
	
***************************************************************************************
*** Table A.7: Standard errors
***************************************************************************************
use "AICM.dta",clear	

  /*  Estimate 5 different specifications:	
	(a) s.e. clustered at cell-level
	(b) Conley s.e. / 500  km / 100.000 months 
	(c) Conley s.e. / 100  km / 100.000 months 	
	(d) Conley s.e. / 100  km / 5 years	
	(e) Conley s.e. / 100  km / 1 years */	

	local vars "asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm"
	
	* battles
		eststo clear
		eststo: xi:quietly reghdfe dbattles `vars', absorb(yrmth cell) cluster(cell) 				
		eststo: xi:quietly my_reg2hdfespatial dbattles `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 				
		eststo: xi:quietly my_reg2hdfespatial dbattles `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(100) lagcutoff(100000) 				
		eststo: xi:quietly my_reg2hdfespatial dbattles `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(100) lagcutoff(60) 				
		eststo: xi:quietly my_reg2hdfespatial dbattles `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(100) lagcutoff(12) 				
		esttab using "TableA7_battles.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 
	
	* violence
		eststo clear
		eststo: xi:quietly reghdfe dviolence `vars', absorb(yrmth cell) cluster(cell) 				
		eststo: xi:quietly my_reg2hdfespatial dviolence `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 				
		eststo: xi:quietly my_reg2hdfespatial dviolence `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(100) lagcutoff(100000) 				
		eststo: xi:quietly my_reg2hdfespatial dviolence `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(100) lagcutoff(60) 				
		eststo: xi:quietly my_reg2hdfespatial dviolence `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(100) lagcutoff(12) 				
		esttab using "TableA7_violence.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 
	
	* riots
		eststo clear
		eststo: xi:quietly reghdfe driots `vars', absorb(yrmth cell) cluster(cell) 				
		eststo: xi:quietly my_reg2hdfespatial driots `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 				
		eststo: xi:quietly my_reg2hdfespatial driots `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(100) lagcutoff(100000) 				
		eststo: xi:quietly my_reg2hdfespatial driots `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(100) lagcutoff(60) 				
		eststo: xi:quietly my_reg2hdfespatial driots `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(100) lagcutoff(12) 				
		esttab using "TableA7_riots.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 

	* looting
		eststo clear
		eststo: xi:quietly reghdfe dlooting `vars', absorb(yrmth cell) cluster(cell) 				
		eststo: xi:quietly my_reg2hdfespatial dlooting `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 				
		eststo: xi:quietly my_reg2hdfespatial dlooting `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(100) lagcutoff(100000) 				
		eststo: xi:quietly my_reg2hdfespatial dlooting `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(100) lagcutoff(60) 				
		eststo: xi:quietly my_reg2hdfespatial dlooting `vars', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(100) lagcutoff(12) 					
		esttab using "TableA7_looting.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 
	

***************************************************************************************
*** Table A.8: Spatial spillovers 1
***************************************************************************************
use "AICM.dta",clear	

	* Panel A
	local conflict "conflict_adj"		
	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm `conflict', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm `conflict', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm `conflict', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm `conflict', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "TableA8a.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 
	
	* Panel B
	local conflict "conflict_adj l1conflict_adj l2conflict_adj l3conflict_adj l4conflict_adj"		
	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm `conflict', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm `conflict', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm `conflict', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm `conflict', timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "TableA8b.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 


***************************************************************************************
*** Table A.9: Spatial spillovers 2
***************************************************************************************
use "AICM.dta",clear	
		
	bysort cell:egen everlsmp=max(LSMp)
	replace everlsmp=1 if everlsmp!=0
	
	* Panel A
	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles asmXprice LSMrXprice LSMr LSMp_adj LSMp_in_asm_adj if everlsmp==0, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence asmXprice LSMrXprice LSMr LSMp_adj LSMp_in_asm_adj if everlsmp==0, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting asmXprice LSMrXprice LSMr LSMp_adj LSMp_in_asm_adj if everlsmp==0, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots asmXprice LSMrXprice LSMr LSMp_adj LSMp_in_asm_adj if everlsmp==0, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "TableA9a.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 
			
	* Panel B		
	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles asmXprice LSMrXprice LSMr LSMp_adj LSMp_in_asm_adj LSMp_adj2 LSMp_in_asm_adj2 if everlsmp==0, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence asmXprice LSMrXprice LSMr LSMp_adj LSMp_in_asm_adj LSMp_adj2 LSMp_in_asm_adj2 if everlsmp==0, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting asmXprice LSMrXprice LSMr LSMp_adj LSMp_in_asm_adj LSMp_adj2 LSMp_in_asm_adj2 if everlsmp==0, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots asmXprice LSMrXprice LSMr LSMp_adj LSMp_in_asm_adj LSMp_adj2 LSMp_in_asm_adj2 if everlsmp==0, timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "TableA9b.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 
	
	
***************************************************************************************
*** Table A.10: Conflict intensity
***************************************************************************************
use "AICM.dta",clear		
	
	* number of conflict events
	local vars "asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm"
	eststo clear
	eststo: xi:quietly reghdfe nbattles `vars' if nbattles<p95nbattles, absorb(yrmth cell) cluster(cell) 				
	eststo: xi:quietly reghdfe nviolence `vars' if nviolence<p95nviolence, absorb(yrmth cell) cluster(cell) 				
	eststo: xi:quietly reghdfe nlooting `vars' if nlooting<p95nlooting, absorb(yrmth cell) cluster(cell) 				
	eststo: xi:quietly reghdfe nriots `vars' if nriots<p95nriots, absorb(yrmth cell) cluster(cell) 				
	esttab using "TableA10a.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 		
	
	* fatal events
	local vars "asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm"
	eststo clear
	eststo: xi:quietly reghdfe dfatalities `vars', absorb(yrmth cell) cluster(cell) 
	eststo: xi:quietly reghdfe nfatalities `vars' if nfatalities<p95nfatalities, absorb(yrmth cell) cluster(cell) 
	esttab using "TableA10b.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 	
		
		
***************************************************************************************
*** Table A.11: Using lagged mineral prices
***************************************************************************************
use "AICM.dta",clear		
	
	* Panel A
	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles asmXpriceL1 LSMrXpriceL1 LSMpXpriceL1 LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence asmXpriceL1 LSMrXpriceL1 LSMpXpriceL1 LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting asmXpriceL1 LSMrXpriceL1 LSMpXpriceL1 LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots asmXpriceL1 LSMrXpriceL1 LSMpXpriceL1 LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "TableA11a.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 

	* Panel B
	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles asmXpriceL6 LSMrXpriceL6 LSMpXpriceL6 LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence asmXpriceL6 LSMrXpriceL6 LSMpXpriceL6 LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting asmXpriceL6 LSMrXpriceL6 LSMpXpriceL6 LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots asmXpriceL6 LSMrXpriceL6 LSMpXpriceL6 LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "TableA11b.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 	
	
	
***************************************************************************************
*** Table A.12: Cell-year observations
***************************************************************************************
use "AICM.dta",clear	
	
	keep dbattles dviolence driots dlooting nbattles nviolence nriots nlooting asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm yrmth cell year month point_y point_x

	collapse (sum) dbattles dviolence driots dlooting nbattles nviolence nriots nlooting (mean) asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm point_y point_x, by(cell year)

	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(year) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(year) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(year) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(year) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "TableA12.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 
		
	
	
***************************************************************************************
*** Table A.13: Distinguishing between state and non-state armed actors
***************************************************************************************
use "AICM.dta",clear		
	
	eststo clear
	eststo: xi:quietly my_reg2hdfespatial dbattles_nog asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dbattles_g asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence_nog asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dviolence_g asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting_nog asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial dlooting_g asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots_nog asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	eststo: xi:quietly my_reg2hdfespatial driots_g asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm , timevar(yrmth) panelvar(cell) lat(point_y) lon(point_x) distcutoff(500) lagcutoff(100000) 	 				
	esttab using "TableA13.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 
	
	
	
***************************************************************************************
*** Table A.14: Controlling for rainfall shocks and seasons
***************************************************************************************
use "AICM.dta",clear		
	
	local vars "asmXprice LSMrXprice LSMpXprice LSMr LSMp LSMr_in_asm LSMp_in_asm"
	eststo clear
	eststo: xi:quietly reghdfe dbattles `vars' rain_anomalyL0-rain_anomalyL12 dry wet, absorb(yrmth cell) cluster(cell) 
	eststo: xi:quietly reghdfe dviolence `vars' rain_anomalyL0-rain_anomalyL12 dry wet, absorb(yrmth cell) cluster(cell) 
	eststo: xi:quietly reghdfe dlooting `vars' rain_anomalyL0-rain_anomalyL12 dry wet, absorb(yrmth cell) cluster(cell) 
	eststo: xi:quietly reghdfe driots `vars' rain_anomalyL0-rain_anomalyL12 dry wet, absorb(yrmth cell) cluster(cell) 
	esttab using "TableA14.rtf", replace b(%6.4f) se(%6.4f) star(* 0.1 ** 0.05 *** 0.01) 

	
